package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-16 16:29
 **/
public class LeetCode2138 {

    public String[] divideString(String s, int k, char fill) {
        int n = s.length();
        List<String> list = new ArrayList<>();
        int i = 0;
        while (i < n) {
            if (n - i > k) {
                list.add(s.substring(i, i + k));
                i += k;
            } else {
                StringBuilder builder = new StringBuilder();
                builder.append(s.substring(i));
                while (builder.length() < k) {
                    builder.append(fill);
                }
                list.add(builder.toString());
                break;
            }
        }

        return list.toArray(new String[0]);
    }

}
